﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Contracts.Report;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Orm.DataEntity;
using System.ComponentModel;
using Kingdee.BOS.Util;

namespace RCE.K3.YGJD.Business.PlugIn.SAL.Report
{
    [Description("销售出库退货明细表")]
    [HotUpdate]
    public class SalInOutStockReportEdit : SysReportBaseService
    {
        #region
        /// <summary>
        /// 
        /// </summary>
        public override void Initialize()
        {   //初始化
            base.Initialize();
            // 简单账表类型：普通、树形、分页
            this.ReportProperty.ReportType = ReportType.REPORTTYPE_NORMAL;
            this.IsCreateTempTableByPlugin = false;
            //是否分组汇总
            this.ReportProperty.IsGroupSummary = true;
        }
        /// <summary>
        /// 获取过滤条件信息(构造单据信息)
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public override ReportTitles GetReportTitles(IRptParams filter)
        {
            ReportTitles reportTitles = new ReportTitles();
            DynamicObject customFilter = filter.FilterParameter.CustomFilter;
            if (customFilter != null)
            {
                string multiOrgnNameValues = this.GetMultiOrgnNameValues(customFilter["F_QAAW_SalOrgid"].ToString());
                string startValue = (customFilter["F_QAAW_StartDate"] == null) ? string.Empty : Convert.ToDateTime(customFilter["F_QAAW_StartDate"]).ToString("yyyy-MM-dd");
                string endValue = (customFilter["F_QAAW_EndDate"] == null) ? string.Empty : Convert.ToDateTime(customFilter["F_QAAW_EndDate"]).ToString("yyyy-MM-dd");
                string startCust = this.getBaseDataNumberValue(customFilter["F_QAAW_SCutId"] as DynamicObject);
                string endCust = this.getBaseDataNumberValue(customFilter["F_QAAW_ECutId"] as DynamicObject);
                string startItem = this.getBaseDataNumberValue(customFilter["F_QAAW_ItemS"] as DynamicObject);
                string endItem = this.getBaseDataNumberValue(customFilter["F_QAAW_ItemE"] as DynamicObject);
                reportTitles.AddTitle("F_QAAW_SalOrg", multiOrgnNameValues);
                reportTitles.AddTitle("F_QAAW_Date", startValue + "至" + endValue);
                reportTitles.AddTitle("F_QAAW_Cust", startCust + "至" + endCust);
                reportTitles.AddTitle("F_QAAW_Item", startItem + "至" + endItem);
            }
            return reportTitles;
        }

        /// <summary>
        /// 设置单据列
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public override ReportHeader GetReportHeaders(IRptParams filter)
        {
            ReportHeader header = new ReportHeader();
            // 编号
            header.AddChild("FOrgName", new LocaleValue("业务组织", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FBillType", new LocaleValue("单据类型", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FOrderBillNo", new LocaleValue("源单单号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FDate", new LocaleValue("日期", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FBillNo", new LocaleValue("单据编号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FCUSTNUMBER", new LocaleValue("客户编码", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FCustName", new LocaleValue("客户名称", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FCustDept", new LocaleValue("客户归属部门", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FCustGroup", new LocaleValue("客户分组", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FCustCJ", new LocaleValue("客户车间", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FMaterialNumber", new LocaleValue("物料代码", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FMaterialName", new LocaleValue("物料名称", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FGSBM", new LocaleValue("物料归属部门", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FGROUPNAME", new LocaleValue("物料分组", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FQty", new LocaleValue("数量", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FUnitName", new LocaleValue("单位", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FPrice", new LocaleValue("单价", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FTaxPrice", new LocaleValue("含税价", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FAMOUNT", new LocaleValue("金额", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FALLAMOUNT", new LocaleValue("价税合计", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FTAXRATE", new LocaleValue("税率", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FNote", new LocaleValue("基础信息备注", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("F_UIXC_Text321", new LocaleValue("回单确认人员", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("F_UIXC_Text61", new LocaleValue("回单确认时间", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("F_UIXC_Text", new LocaleValue("客户采购订单号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("F_UIXC_Text2", new LocaleValue("明细行客户物料编号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FEntrynote", new LocaleValue("明细行备注", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            return header;
        }

        /// <summary>
        /// 创建临时报表
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="tableName"></param>
        public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
        {
            base.BuilderReportSqlAndTempTable(filter, tableName);
        }

        /// <summary>
        /// 设置汇总列信息
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public override List<SummaryField> GetSummaryColumnInfo(IRptParams filter)
        {
            var result = base.GetSummaryColumnInfo(filter);
            result.Add(new SummaryField("FQty", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.SUM));
            result.Add(new SummaryField("FALLAMOUNT", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.SUM));
            return result;
        }

        /// <summary>
        /// 构建order by语句
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        protected override string BuilderTempTableOrderBySQL(IRptParams filter)
        {
            //排序
            string datasort = Convert.ToString(filter.FilterParameter.SortString);
            string OrderBy;
            if (datasort != "")
            {
                OrderBy = datasort;
            }
            else
            {
                OrderBy = " FDate ";
            }
            return OrderBy;
        }

        /// <summary>
        /// 构建单据select 和字段
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        protected override string BuilderSelectFieldSQL(IRptParams filter)
        {
            string sqlstr = @"/*dialect*/select FID, FOrgName,FBillType,FCustName,FDate,FBillNo,FMaterialNumber,FMaterialName,FGSBM,FGROUPNAME
                               ,FLOCALCURRID,FQty,FUnitName,FCustDept,FCustGroup,FCustCJ,FOrderBillNo,FCUSTNUMBER ,FPRICE,FTaxPrice,FAMOUNT,FALLAMOUNT,FTAXRATE
                                ,FNote,F_UIXC_Text321,F_UIXC_Text61,F_UIXC_Text,F_UIXC_Text2,FEntrynote";
            return sqlstr;
        }


        /// <summary>
        /// 构建from where语句
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        protected override string BuilderFromWhereSQL(IRptParams filter)
        {
            DynamicObject customFilter = filter.FilterParameter.CustomFilter;
            StringBuilder strwhere = new StringBuilder();
            strwhere.AppendLine(@" from 
                                (
select sos.FID,ool.FNAME FOrgName, '销售出库单' FBillType, bc.fnumber FCUSTNUMBER, bcl.FNAME FCustName,
	convert(varchar(200),sos.FDATE,23) FDate ,sos.FBILLNO, bm.FNUMBER FMaterialNumber, bml.FNAME FMaterialName,
	sosf.FLOCALCURRID,sose.FREALQTY  FQty, bul.FNAME FUnitName,sos.FSALEORGID, 
	gsbml.FNAME FGSBM,BMG.FFULLPARENTID,bmgl.fname FGROUPNAME,cast(bmg.FID as varchar(200)) FMATERIALGROUPID,
	khcjl.FNAME FCustCJ,khgsbml.FNAME FCustDept,cgl.FNAME FCustGroup,  soser.FSrcBillNo  FOrderBillNo,
	cast(cg.FID as varchar(200)) FCUSTGROUPID, sosef.FPRICE,sosef.FTAXPRICE, sosef.FAMOUNT, sosef.FALLAMOUNT,sosef.FTAXRATE,
	sos.FNote ,sos.F_UIXC_Text321,sos.F_UIXC_Text61,sos.F_UIXC_Text,sose.F_UIXC_Text2,sose.FNOTE FEntrynote
from T_SAL_OUTSTOCK sos with(nolock)
left join T_SAL_OUTSTOCKENTRY sose with(nolock) on sose.FID= sos.FID
left join T_SAL_OUTSTOCKENTRY_R soser with(nolock) on soser.FENTRYID = sose.FENTRYID
left join T_SAL_OUTSTOCKFIN sosf with(nolock) on sosf.FID = sos.FID
left join T_SAL_OUTSTOCKENTRY_F sosef with(nolock) on sosef.FENTRYID= sose.FENTRYID
left join T_BD_CUSTOMER bc with(nolock) on bc.FCUSTID = sos.FCUSTOMERID
left join T_BD_CUSTOMER_L bcl with(nolock) on bcl.FCUSTID = bc.FCUSTID and bcl.FLOCALEID = 2052
left join T_ORG_ORGANIZATIONS oo with(nolock) on oo.FORGID = sos.FSALEORGID
left join T_ORG_ORGANIZATIONS_L ool with(nolock) on ool.FORGID = oo.FORGID and ool.FLOCALEID = 2052
left join T_BD_MATERIAL bm with(nolock) on bm.FMATERIALID = sose.FMATERIALID
left join T_BD_MATERIAL_L bml with(nolock) on bml.FMATERIALID = bm.FMATERIALID and bml.FLOCALEID = 2052
left join T_BD_CURRENCY curr with(nolock) on curr.FCURRENCYID = sosf.FSETTLECURRID 
left join T_BD_CURRENCY_L currl with(nolock) on currl.FCURRENCYID = sosf.FSETTLECURRID  and currl.FLOCALEID = 2052
left join T_BD_UNIT bu with(nolock) on bu.FUNITID = sose.FUNITID
left join T_BD_UNIT_L bul with(nolock) on bul.FUNITID = bu.FUNITID  and bul.FLOCALEID = 2052
left join T_BD_DEPARTMENT gsbm with(nolock) on gsbm.FDEPTID = bm.F_UIXC_GSSYB
left join T_BD_DEPARTMENT_L gsbml with(nolock) on gsbml.FDEPTID = gsbm.FDEPTID and gsbml.FLOCALEID = 2052
left join T_BD_MATERIALGROUP bmg with(nolock) on bmg.FID = bm.FMaterialGroup
left join T_BD_MATERIALGROUP_L bmgl with(nolock) on bmgl.FID = bmg.FID and bmgl.FLOCALEID= 2052
left join UIXC_t_Cust100002 khcj with(nolock) on khcj.FID = sos.F_UIXC_BASE
left join UIXC_t_Cust100002_L khcjl with(nolock) on khcjl.FID = khcj.FID and khcjl.FLOCALEID = 2052
left join T_BD_CUSTOMERGROUP cg with(nolock) on cg.FID = bc.FPRIMARYGROUP
left join T_BD_CUSTOMERGROUP_L cgl with(nolock) on cgl.FID = cg.FID and cgl.FLOCALEID = 2052
left join T_BD_DEPARTMENT khgsbm with(nolock) on khgsbm.FDEPTID = bc.F_UIXC_GSSYB
left join T_BD_DEPARTMENT_L khgsbml with(nolock) on khgsbml.FDEPTID = khgsbm.FDEPTID
where sos.FDOCUMENTSTATUS = 'C'
union all
select sos.FID,ool.FNAME FOrgName, '销售退货单' FBillType, bc.fnumber FCUSTNUMBER, bcl.FNAME FCustName,
	convert(varchar(200),sos.FDATE,23) ,sos.FBILLNO, bm.FNUMBER FMaterialNumber, bml.FNAME FMaterialName,
	sosf.FLOCALCURRID,-sose.FREALQTY  FQty, bul.FNAME FUnitName,sos.FSALEORGID, 
	gsbml.FNAME FGSBM,BMG.FFULLPARENTID,bmgl.fname FGROUPNAME,cast(bmg.FID as varchar(200))  FMATERIALGROUPID,
	khcjl.FNAME FCustCJ,khgsbml.FNAME FCustDept,cgl.FNAME FCustGroup, soser.FSrcBillNo FOrderBillNo,
	cast(cg.FID as varchar(200)) FCUSTGROUPID,sosef.FPRICE,sosef.FTAXPRICE, -sosef.FAMOUNT, -sosef.FALLAMOUNT,sosef.FTAXRATE,
	sos.FNote ,'','','','',sose.FNOTE FEntrynote
from T_SAL_RETURNSTOCK sos with(nolock)
left join T_SAL_RETURNSTOCKENTRY sose with(nolock) on sose.FID= sos.FID
left join T_SAL_RETURNSTOCKENTRY_r soser with(nolock) on soser.FENTRYID= sose.FENTRYID
left join T_SAL_RETURNSTOCKFIN sosf with(nolock) on sosf.FID = sos.FID
left join T_SAL_RETURNSTOCKENTRY_F sosef with(nolock) on sosef.FENTRYID= sose.FENTRYID
left join T_BD_CUSTOMER bc with(nolock) on bc.FCUSTID = sos.FRetcustId
left join T_BD_CUSTOMER_L bcl with(nolock) on bcl.FCUSTID = bc.FCUSTID and bcl.FLOCALEID = 2052
left join T_ORG_ORGANIZATIONS oo with(nolock) on oo.FORGID = sos.FSALEORGID
left join T_ORG_ORGANIZATIONS_L ool with(nolock) on ool.FORGID = oo.FORGID and ool.FLOCALEID = 2052
left join T_BD_MATERIAL bm with(nolock) on bm.FMATERIALID = sose.FMATERIALID
left join T_BD_MATERIAL_L bml with(nolock) on bml.FMATERIALID = bm.FMATERIALID and bml.FLOCALEID = 2052
left join T_BD_CURRENCY curr with(nolock) on curr.FCURRENCYID = sosf.FSETTLECURRID 
left join T_BD_CURRENCY_L currl with(nolock) on currl.FCURRENCYID = sosf.FSETTLECURRID  and currl.FLOCALEID = 2052
left join T_BD_UNIT bu with(nolock) on bu.FUNITID = sose.FUNITID
left join T_BD_UNIT_L bul with(nolock) on bul.FUNITID = bu.FUNITID  and bul.FLOCALEID = 2052
left join T_BD_DEPARTMENT gsbm with(nolock) on gsbm.FDEPTID = bm.F_UIXC_GSSYB
left join T_BD_DEPARTMENT_L gsbml with(nolock) on gsbml.FDEPTID = gsbm.FDEPTID and gsbml.FLOCALEID = 2052
left join T_BD_MATERIALGROUP bmg with(nolock) on bmg.FID = bm.FMaterialGroup
left join T_BD_MATERIALGROUP_L bmgl with(nolock) on bmgl.FID = bmg.FID and bmgl.FLOCALEID= 2052
left join UIXC_t_Cust100002 khcj with(nolock) on khcj.FID = sos.F_UIXC_khcj
left join UIXC_t_Cust100002_L khcjl with(nolock) on khcjl.FID = khcj.FID
left join T_BD_CUSTOMERGROUP cg with(nolock) on cg.FID = bc.FPRIMARYGROUP
left join T_BD_CUSTOMERGROUP_L cgl with(nolock) on cgl.FID = cg.FID and cgl.FLOCALEID = 2052
left join T_BD_DEPARTMENT khgsbm with(nolock) on khgsbm.FDEPTID = bc.F_UIXC_GSSYB
left join T_BD_DEPARTMENT_L khgsbml with(nolock) on khgsbml.FDEPTID = khgsbm.FDEPTID
where sos.FDOCUMENTSTATUS = 'C'
) t1  Where 1=1 ");

            //组织
            string org = string.IsNullOrWhiteSpace(customFilter["F_QAAW_SalOrgid"].ToString())
                ? " " : string.Format(" AND FSALEORGID IN ({0}) ", Convert.ToString(customFilter["F_QAAW_SalOrgid"]));
            strwhere.AppendLine(org);
            // 单据类型
            string billType = string.IsNullOrWhiteSpace(customFilter["F_QAAW_BillType"].ToString())
                ? " " : string.Format(" and FBillType in ({0})", $"'{customFilter["F_QAAW_BillType"].ToString().Replace(",", "','")}'");

            strwhere.AppendLine(billType);
            //日期
            string startValue = (customFilter["F_QAAW_StartDate"] == null)
                ? DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")
                : Convert.ToDateTime(customFilter["F_QAAW_StartDate"]).ToString("yyyy-MM-dd");
            string endValue = (customFilter["F_QAAW_EndDate"] == null)
                ? DateTime.Now.ToString("yyyy-MM-dd")
                : Convert.ToDateTime(customFilter["F_QAAW_EndDate"]).ToString("yyyy-MM-dd");
            strwhere.AppendLine(string.Format(" AND FDate>='{0}' and FDate<='{1}' ", startValue, endValue));

            string startCust = this.getBaseDataNumberValue(customFilter["F_QAAW_SCutId"] as DynamicObject);
            if (!string.IsNullOrWhiteSpace(startCust))
            {
                strwhere.AppendLine($" and FCUSTNUMBER >= '{startCust}'");
            }
            string endCust = this.getBaseDataNumberValue(customFilter["F_QAAW_ECutId"] as DynamicObject);
            if (!string.IsNullOrWhiteSpace(endCust))
            {
                strwhere.AppendLine($" and FCUSTNUMBER <= '{endCust}'");
            }
            string startItem = this.getBaseDataNumberValue(customFilter["F_QAAW_ItemS"] as DynamicObject);
            if (!string.IsNullOrWhiteSpace(startItem))
            {
                strwhere.AppendLine($" and FMaterialNumber <= '{startItem}'");
            }
            string endItem = this.getBaseDataNumberValue(customFilter["F_QAAW_ItemE"] as DynamicObject);
            if (!string.IsNullOrWhiteSpace(endItem))
            {
                strwhere.AppendLine($" and FMaterialNumber >= '{endItem}'");
            }
            string F_QAAW_SBillNo = customFilter["F_QAAW_SBillNo"] == null ? "" : customFilter["F_QAAW_SBillNo"].ToString();
            if (!string.IsNullOrWhiteSpace(F_QAAW_SBillNo))
            {
                strwhere.AppendLine($" and FBILLNO <= '{F_QAAW_SBillNo}'");
            }
            string F_QAAW_EBillNo = customFilter["F_QAAW_EBillNo"] == null ? "" : customFilter["F_QAAW_EBillNo"].ToString();
            if (!string.IsNullOrWhiteSpace(F_QAAW_EBillNo))
            {
                strwhere.AppendLine($" and FBILLNO >= '{F_QAAW_EBillNo}'");
            }


            string FSMaterialGroup = this.getBaseDataNumberValue(customFilter["FSMaterialGroup"] as DynamicObject);
            string FEMaterialGroup = this.getBaseDataNumberValue(customFilter["FEMaterialGroup"] as DynamicObject);
            strwhere.AppendLine(getFilterMaterialGroup(FSMaterialGroup,FEMaterialGroup));
            string FSCustGroup = this.getBaseDataNumberValue(customFilter["FSCustGroup"] as DynamicObject);
            string FECustGroup = this.getBaseDataNumberValue(customFilter["FECustGroup"] as DynamicObject);
            strwhere.AppendLine(getFilterCustomerGroup(FSCustGroup, FECustGroup));

            if (!string.IsNullOrWhiteSpace(filter.FilterParameter.FilterString))
            {
                strwhere.AppendLine(" and " + filter.FilterParameter.FilterString);
            }

            string execSql = strwhere.ToString();
            return execSql;
        }
        #endregion

        public string getFilterMaterialGroup(string FSMaterialGroup, string FEMaterialGroup)
        {
            HashSet<string> setGroup = new HashSet<string>();
            if (!string.IsNullOrWhiteSpace(FSMaterialGroup) || !string.IsNullOrWhiteSpace(FEMaterialGroup))
            {
                string sql = "select FID from T_BD_MATERIALGROUP where  1=1  ";
                if (!string.IsNullOrWhiteSpace(FSMaterialGroup))
                {
                    sql += $" and FNUMBER >='{FSMaterialGroup}' ";
                }

                if (!string.IsNullOrWhiteSpace(FEMaterialGroup))
                {
                    sql += $" and FNUMBER <='{FEMaterialGroup}' ";
                }
                DynamicObjectCollection mGroup = DBUtils.ExecuteDynamicObject(Context, sql);
                if (mGroup != null)
                {
                    foreach (var item in mGroup)
                    {
                        string sql1 = $"select FID from T_BD_MATERIALGROUP where fid = {item["FID"].ToString()} or FFULLPARENTID like '%{item["FID"].ToString()}%'";
                        DynamicObjectCollection CmGroup = DBUtils.ExecuteDynamicObject(Context, sql);
                        foreach (var item1 in CmGroup)
                        {
                            setGroup.Add(item1["FID"].ToString());
                        }
                    }
                }
            }
            string strMapGroup = "'0'";
            foreach (var item in setGroup)
            {
                strMapGroup += $",'{item}'";
            }
            if (setGroup.Count > 0)
            {
                return $" and FMATERIALGROUPID in ({strMapGroup})";
            }
            return "";
        }

        public string getFilterCustomerGroup(string FSCustGroup, string FECustGroup)
        {
            HashSet<string> setGroup = new HashSet<string>();
            if (!string.IsNullOrWhiteSpace(FSCustGroup) || !string.IsNullOrWhiteSpace(FECustGroup))
            {
                string sql = "select FID from T_BD_CUSTOMERGROUP where  1=1  ";
                if (!string.IsNullOrWhiteSpace(FSCustGroup))
                {
                    sql += $" and FNUMBER >='{FSCustGroup}' ";
                }

                if (!string.IsNullOrWhiteSpace(FECustGroup))
                {
                    sql += $" and FNUMBER <='{FECustGroup}' ";
                }
                DynamicObjectCollection mGroup = DBUtils.ExecuteDynamicObject(Context, sql);
                if (mGroup != null)
                {
                    foreach (var item in mGroup)
                    {
                        string sql1 = $"select FID from T_BD_CUSTOMERGROUP where fid = {item["FID"].ToString()} or FFULLPARENTID like '%{item["FID"].ToString()}%'";
                        DynamicObjectCollection CmGroup = DBUtils.ExecuteDynamicObject(Context, sql);
                        foreach (var item1 in CmGroup)
                        {
                            setGroup.Add(item1["FID"].ToString());
                        }
                    }
                }
            }
            string strMapGroup = "'0'";
            foreach (var item in setGroup)
            {
                strMapGroup += $",'{item}'";
            }
            if (setGroup.Count > 0)
            {
                return $" and FCUSTGROUPID in ({strMapGroup})";
            }
            return "";
        }

        /// <summary>
        /// 组织名称
        /// </summary>
        /// <param name="orgIdStrings"></param>
        /// <returns></returns>
        private string GetMultiOrgnNameValues(string orgIdStrings)
        {
            List<string> list = new List<string>();
            string result = string.Empty;
            if (orgIdStrings.Trim().Length > 0)
            {
                IQueryService service = Kingdee.BOS.Contracts.ServiceFactory.GetService<IQueryService>(base.Context);
                QueryBuilderParemeter para = new QueryBuilderParemeter
                {
                    FormId = "ORG_Organizations",
                    SelectItems = SelectorItemInfo.CreateItems("FNAME"),
                    FilterClauseWihtKey = string.Format(" FORGID IN ({0}) AND FLOCALEID={1}", orgIdStrings, base.Context.UserLocale.LCID)
                };
                DynamicObjectCollection dynamicObjectCollection = service.GetDynamicObjectCollection(base.Context, para, null);
                foreach (DynamicObject current in dynamicObjectCollection)
                {
                    list.Add(current["FNAME"].ToString());
                }
                if (list.Count > 0)
                {
                    result = string.Join(",", list.ToArray());
                }
            }
            return result;
        }
        /// <summary>
        /// 基础资料名称
        /// </summary>
        /// <param name="dyobj"></param>
        /// <returns></returns>
        private string GetBaseDataNameValue(DynamicObjectCollection dyobj)
        {
            string name = "";
            foreach (DynamicObject dynbj in dyobj)
            {
                if (dynbj != null || !dynbj.DynamicObjectType.Properties.Contains("Name"))
                {
                    DynamicObject dynbj2 = (DynamicObject)dynbj[2];
                    name = name + ",'" + dynbj2["Name"].ToString() + "'";
                }
            }
            if (name.Length > 0)
            {
                name = name.Substring(1, name.Length - 1);
            }
            return name;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dyobj"></param>
        /// <returns></returns>
        public string getBaseDataNumberValue(DynamicObject dyobj)
        {
            if (dyobj == null)
            {
                return "";
            }
            string number = "";
            if (dyobj.DynamicObjectType.Properties.Contains("Number"))
            {
                number = dyobj["Number"].ToString();
            }
            return number;
        }
    }
}
